package com.zjmzxfzhl.integrityconstraint.test;

import com.zjmzxfzhl.integrityconstraint.annotation.IntegrityConstraintAnnotation;
import com.zjmzxfzhl.integrityconstraint.annotation.OperationTypeEnum;
import com.zjmzxfzhl.integrityconstraint.annotation.ValueAnnotation;
import com.zjmzxfzhl.integrityconstraint.annotation.VerifyAnnotation;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class SomeService {
    @IntegrityConstraintAnnotation(operationType = OperationTypeEnum.SAVE, businessKey = "#businessKey",
            saveVerify = @VerifyAnnotation(type = "verifyType1", valuesExpression = "#someParam.paramName,#someParam2.paramName2->changeParamName2")
    )
    public String verifyType1(String businessKey, Map<String, Object> someParam, Map<String, Object> someParam2) {
        return "verifyType1";
    }

    @IntegrityConstraintAnnotation(operationType = OperationTypeEnum.SAVE, businessKey = "#businessKey",
            saveVerify = @VerifyAnnotation(typeExpression = "#someParam.verifyType", valuesExpression = "#someParam.paramName,#someParam2.paramName3->changeParamName3")
    )
    public String verifyType2(String businessKey, Map<String, Object> someParam, Map<String, Object> someParam2) {
        return "verifyType2";
    }

    @IntegrityConstraintAnnotation(operationType = OperationTypeEnum.SAVE, businessKey = "#businessKey",
            saveVerify = @VerifyAnnotation(type = "verifyType3", valuesExpression = "#someBo.someBoName,#someBo.someBoAmt")
    )
    public String verifyType3(String businessKey, SomeBo someBo, Map<String, Object> someParam2) {
        return "verifyType3";
    }

    @IntegrityConstraintAnnotation(operationType = OperationTypeEnum.SAVE, businessKey = "#businessKey", expire = 2L,
            saveVerify = @VerifyAnnotation(type = "verifyType4", valuesExpression = "#someBo.someBoName,#someBo.someBoAmt")
    )
    public String verifyType4(String businessKey, SomeBo someBo, Map<String, Object> someParam2) {
        return "verifyType4";
    }

    @IntegrityConstraintAnnotation(operationType = OperationTypeEnum.CHECK, businessKey = "#businessKey",
            checkVerifys = {
                    @VerifyAnnotation(type = "verifyType1", valuesExpression = "#someParam.paramName,#someParam2.paramName2->changeParamName2", conditionExpression = "#someParam.paramName2>11"),
                    @VerifyAnnotation(type = "verifyType2", valuesExpression = "#someParam.paramName,#someParam2.paramName3->changeParamName3"),
                    @VerifyAnnotation(type = "verifyType3", valuesExpression = "#someBo.someBoName,#someBo.someBoAmt")
            }
    )
    public String someCommit(String businessKey, Map<String, Object> someParam, Map<String, Object> someParam2, SomeBo someBo) {
        return "checkOk";
    }

    @IntegrityConstraintAnnotation(operationType = OperationTypeEnum.CHECK, businessKey = "#businessKey",
            checkVerifys = {
                    @VerifyAnnotation(type = "verifyType1", valuesExpression = "#someParam.paramName,#someParam2.paramName2->changeParamName2", conditionExpression = "#someParam.paramName2>11"),
                    @VerifyAnnotation(type = "verifyType2", valuesExpression = "#someParam.paramName,#someParam2.paramName3->changeParamName3"),
                    @VerifyAnnotation(type = "verifyType3", valuesExpression = "#someBo.someBoName,#someBo.someBoAmt"),
                    @VerifyAnnotation(type = "verifyType4", valuesExpression = "#someBo.someBoName,#someBo.someBoAmt")
            }
    )
    public String someCommit2(String businessKey, Map<String, Object> someParam, Map<String, Object> someParam2, SomeBo someBo) {
        return "checkOk";
    }

    @IntegrityConstraintAnnotation(operationType = OperationTypeEnum.CHECK, businessKey = "#businessKey",
            checkVerifys = {
                    @VerifyAnnotation(type = "verifyType1", conditionExpression = "#someParam.paramName2>11", values = {
                            @ValueAnnotation(key = "paramName", valueExpression = "#someParam.paramName"),
                            @ValueAnnotation(key = "changeParamName2", valueExpression = "#someParam2.paramName2")
                    }),
                    @VerifyAnnotation(type = "verifyType2", values = {
                            @ValueAnnotation(key = "paramName", valueExpression = "#someParam.paramName"),
                            @ValueAnnotation(key = "changeParamName3", valueExpression = "#someParam2.paramName3")
                    }),
                    @VerifyAnnotation(type = "verifyType3", values = {
                            @ValueAnnotation(key = "someBoName", valueExpression = "#someBo.someBoName"),
                            @ValueAnnotation(key = "someBoAmt", valueExpression = "#someBo.someBoAmt")
                    }),
                    @VerifyAnnotation(type = "verifyType4", values = {
                            @ValueAnnotation(key = "someBoName", valueExpression = "#someBo.someBoName"),
                            @ValueAnnotation(key = "someBoAmt", valueExpression = "#someBo.someBoAmt")
                    })
            }
    )
    public String someCommit3(String businessKey, Map<String, Object> someParam, Map<String, Object> someParam2, SomeBo someBo) {
        return "checkOk";
    }
}
